{% extends "base.html" %}
{% block content %}
{% load static %}

<div class="table-responsive">
            <table class="table table-striped">
              <thead>
                <tr>
                  <th>title</th>
                  <th>body</th>
                  <th>time</th>
                  <th>operation</th>
                </tr>
              </thead>
              <tbody>
                  {% for device in Devices %}
                <tr>
                <td id="title">{{device.id}}</td>
                <td id="body">{{device.ip_address}}</td>
                <td id="time">{{device.hostname}}</td>
                <td>
                        <button type="button" class="btn btn-default btn-xs" onclick="edititem(this)">
                        <span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
                        </button>
                        <button type="button" class="btn btn-default btn-xs" onclick="getrmitem(this)">
                        <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
                        </button>
                </td>
                </tr>

                <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
                  <div class="modal-dialog" role="document">
                    <div class="modal-content">
                      <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                        <h4 class="modal-title" id="exampleModalLabel">New message</h4>
                      </div>
                      <div class="modal-body">
                        <form>
                          <div class="form-group">
                            <label class="control-label">Title:</label>
                            <input type="text" class="form-control" id="titletext">
                          </div>
                          <div class="form-group">
                            <label class="control-label">Body:</label>
                            <textarea class="form-control" id="bodytext"></textarea>
                          </div>
                        </form>
                      </div>
                      <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="button" class="btn btn-primary" οnclick="edititem(this)">Save</button>
                      </div>
                    </div>
                  </div>
                </div>

                {% endfor %}
             </tbody>
          </table>
</div>

<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script src="http://cdn.bootcss.com/bootstrap/2.3.1/js/bootstrap-transition.js"></script>
<script src="http://cdn.bootcss.com/bootstrap/2.3.1/js/bootstrap-modal.js"></script>
<script>
function edititem(obj){
    var tr=$(obj).parent().parent();
    var title = tr.children("td#title").text();
    var body = tr.children("td#body").text();
    $('#titletext').val(title);
    $('#bodytext').val(body);
    $('#exampleModal').modal('show')

    };
</script>
{% endblock %}